package realtime

import (
	"context"
	"stock/server/internal/pkg/stock/api"
	"stock/server/internal/pkg/threadutil"
	"time"
)

type Realtime struct {
	ctx context.Context
}

func (o Realtime) Run() {
	fn := func() {
		for {
			timer := time.NewTimer(0 * time.Second)
			select {
			case <-o.ctx.Done():
				return

			case <-timer.C:
				// 优先执行一次, 获取最后的数据
				// 之后按照时间间隔执行

				_, _ = api.NewStockApi(api.TencentApi).Realtime([]api.Code{})
			}
		}
	}

	threadutil.GoSafe(fn)
}
